import heapq
from math import sqrt

n = int(input())


def evaluDis(s1, s2, y1, y2):
    return sqrt((y1 - s1) ** 2 + (y2 - s2) ** 2) / sqrt(5)


def Astar(x1, y1, x2, y2):
    distance = [[float('inf') for _ in range(1001)] for _ in range(1001)]  # 实际距离

    distance[x1][y1] = 0
    visited = [[False for _ in range(1001)] for _ in range(1001)]  # 是否访问过
    heap = [(evaluDis(x1, y1, x2, y2) + 0, (x1, y1))]  # 总代价 和该点坐标
    while heap:
        dis, (x, y) = heapq.heappop(heap)
        if (x, y) == (x2, y2): break
        for nx, ny in [(x + 1, y + 2), (x - 1, y + 2), (x + 2, y + 1), (x - 2, y + 1), (x + 1, y - 2), (x - 1, y - 2),
                       (x + 2, y - 1), (x - 2, y - 1)]:
            if nx < 1 or nx >= 1001: continue
            if ny < 1 or ny >= 1001: continue
            # if visited[nx][ny]: continue
            if distance[nx][ny] < distance[x][y] + 1: continue
            distance[nx][ny] = distance[x][y] + 1
            visited[nx][ny] = True
            heapq.heappush(heap, (distance[nx][ny] + evaluDis(nx, ny, x2, y2), (nx, ny)))
    return distance[x2][y2]


for _ in range(n):
    p = list(map(int, input().strip().split()))
    print(Astar(*p))
